var g_TextMessage;
function TextMessage(id){
    this.box = document.getElementById(id);
    this.init = function(txt){
        this.live = true;
        this.start = new Date();
        //this.text = txt;
        this.box.innerHTML=txt;
        this.box.style.visibility="visible";
    }

    this.update = function(){
        if(!this.live)
            return;
        var cur = new Date();
        if((cur - this.start) > 2000){
            this.box.style.visibility="hidden";
            this.live=false;
        }
    }
}

var g_highScores = new Array();
var g_hsNames = new Array();
function saveHighScores()
{ //save the highscores to local store.
    var score_set = false;
    var hs = new Array();
    var hsn = new Array();
    for(var i = 0, j = 0; i < g_numHighScores; i++)
    {
        if(g_highScores[j] < g_player.score && score_set==false)
        {
            hs.push(g_player.score);
            hsn.push(document.getElementById("pname").value);
            score_set = true;
        }
        else
        {
            hs.push(g_highScores[j]);
            hsn.push(g_hsNames[j]);
            j++;
        } 
    }
    document.getElementById("hsbutton").value="saved";
    document.getElementById("hsbutton").disabled=true;
    window.localStorage['highscores'] = hs;
    window.localStorage['hsnames'] = hsn;
}

function getHighScores()
{
    var score_set = false;
    var str = '<table>'
    for(var i = 0, j = 0; i < g_numHighScores; i++)
    {
        if(g_highScores[j] < g_player.score && score_set==false)
        {
            str += "<tr><td><input type=text value=\"---\" id=\"pname\">";
            str += "<input type=button value=\"submit\" id=\"hsbutton\" onClick=\"saveHighScores();\"></td><td>"+g_player.score+"</td>";
            score_set = true;
        }
        else
        {
            str += '<tr><td>'+g_hsNames[j]+"</td><td>"+g_highScores[j]+"</td></tr>";
            j++;
        } 
    }
    str += '</table>';
    return str;
}

function PauseButtonClicked()
{
    if(g_pausebutton.value== "||")
    {
        g_pausebutton.value=">";
        snd_bgscore.pause();
        g_startGame=false;
        g_mesg.innerHTML="Paused";
        g_mesg.style.visibility="visible";
    }
    else
    {
        g_mesg.style.visibility="hidden";
        g_pausebutton.value="||";
        snd_bgscore.play();
        g_startGame=true;
    }
}

